#include "cmaterial.h"

CMaterial * CMaterial::voidContext = new CMaterial(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true, 1.0, 1.0);
CMaterial * CMaterial::airContext = new CMaterial(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true, 1.0003, 1.0003);

CMaterial::CMaterial()
{
}

CMaterial::CMaterial(float r, float g, float b, float reflection, float rS, float gS, float bS, float PowerS, bool bTrans, float n,  float refrac)
{
	this->r = r;
	this->g = g;
	this->b = b;
	this->reflection = reflection;
	this->refraction = refrac;
	this->bTransparent = bTrans;
	this->n = n;
	this->nR = n;
	this->nG = n;
	this->nB = n;
	this->rS = rS;
	this->gS = gS;
	this->bS = bS;
	this->powerS = PowerS;
}

CMaterial::CMaterial(const CMaterial & orig)
{
	this->r = orig.r;
	this->g = orig.g;
	this->b = orig.b;
	this->reflection = orig.reflection;
	this->refraction = orig.refraction;
	this->bTransparent = orig.bTransparent;
	this->n = orig.n;
	this->nR = orig.nR;
	this->nG = orig.nG;
	this->nB = orig.nB;
	this->rS = orig.rS;
	this->gS = orig.gS;
	this->bS = orig.bS;
	this->powerS = orig.powerS;
}

CMaterial CMaterial::getvoidContext()
{
	return *voidContext;
}

CMaterial CMaterial::getairContext()
{
	return *airContext;
}

void CMaterial::setTransparent(bool bTrans, float N, float refraction)
{
	this->bTransparent = bTrans;
	this->n = N;
	this->nR = N;
	this->nG = N;
	this->nB = N;
	this->refraction = refraction;
}

void CMaterial::setRefractionInd(float nR, float nG, float nB)
{
	if (nR < 1.0)
	{
		this->n = 1.0;
		this->nR = 1.0;
		this->nG = 1.0;
		this->nB = 1.0;
	}
	else
	{
		this->n = nR;
		this->nR = nR;
		if (nG < 1.0 || nB < 1.0)
		{
			this->nG = nR;
			this->nB = nB;
		}
		else
		{
			this->nG = nG;
			this->nB = nB;
		}
	}
}
